package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlConfiguration {
    private static String driver="com.mysql.cj.jdbc.Driver";
    private static String url="jdbc:mysql://localhost:3306/linking_mall";
    private static String user="root";
    private static String pwd="123456";
    private static Connection connection=null;

    public static Connection MysqlConnection(){
        connection=null;
        try {
            Class.forName(driver);
            System.out.println("创建数据库驱动成功!");
            connection= DriverManager.getConnection(url,user,pwd);
            System.out.println("创建数据库连接对象成功!");
        }catch (Exception e){
            System.out.println("数据库连接失败:"+e.getMessage());
        }
        return connection;
    }

    public static boolean CloseConnection(){
        try {
            connection.close();
            return true;
        } catch (SQLException e) {
            System.out.println("数据库连接关闭失败:"+e.getMessage());
            return false;
        }
    }
}
